<!-- sale.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Process Sale</title>
</head>
<body>
    <h1>Process Sale</h1>
    
    <form action="SaleController" method="POST">
        <input type="hidden" name="action" value="startSale">
        <input type="submit" value="Start New Sale">
    </form>

    <form action="SaleController" method="POST">
        <input type="hidden" name="action" value="addItem">
        <label for="itemId">Item ID:</label>
        <input type="text" id="itemId" name="itemId" required>
        <br><br>
        
        <label for="quantity">Quantity:</label>
        <input type="number" id="quantity" name="quantity" required>
        <br><br>

        <input type="submit" value="Add to Sale">
    </form>

    <h2>Sale Summary:</h2>
    <p>Total Sale Amount: ${totalAmount}</p>
    <h3>Items:</h3>
    <ul>
        <c:forEach var="lineItem" items="${lineItems}">
            <li>${lineItem.description.getDescription()} - ${lineItem.getQuantity()} x ${lineItem.getSubtotal().getAmount()}</li>
        </c:forEach>
    </ul>
    
    <form action="SaleController" method="POST">
        <input type="hidden" name="action" value="completeSale">
        <label for="cashTendered">Cash Tendered:</label>
        <input type="number" id="cashTendered" name="cashTendered" required>
        <br><br>
        <input type="submit" value="Complete Sale">
    </form>

    <c:if test="${not empty balance}">
        <h3>Change Due: ${balance}</h3>
    </c:if>
</body>
</html>
